Page({
    data: {
        navigationBar: 0,
        from: {
            type: 0,
            name: '',
            phone: '',
            idCardType: 0,
            idCardNumber: '',
            isDefault: false,
        },
        idCardTypeList: [
            {
                text: '居民身份证',
                value: 0,
            },
            {
                text: '港澳通行证',
                value: 1,
            },
            {
                text: '台湾通行证',
                value: 2,
            },
            {
                text: '护照',
                value: 3,
            },
        ],
        idCardTypeTpy: 0,
        showPopup: false,
    },

    onLoad: function (options) {
        const systemInfo = wx.getSystemInfoSync();
        const menuButtonInfo = wx.getMenuButtonBoundingClientRect();
        this.setData({
            navigationBar: (menuButtonInfo.top - (systemInfo?.statusBarHeight || 0)) * 2 + menuButtonInfo.height,
        });
    },

    onTypeChange: function (e) {
        const type = e.currentTarget.dataset.type;
        this.setData({
            'from.type': parseInt(type, 10)
        });
    },

    onNameInput: function (e) {
        this.setData({
            'from.name': e.detail.value
        });
    },

    onIdTypeChange(event) {
        const {index} = event.detail;
        this.data.idCardTypeTpy = index;
    },


    onIsDefault: function ({detail}) {
        this.setData({
            'from.isDefault': detail
        });
    },

    onSheetOpen: function () {
        this.setData({
            showPopup: true,
        });
    },

    onSheetClose: function () {
        this.setData({
            showPopup: false,
        });
    },

    onIdTypeConfirm() {
        this.onSheetClose();
        this.setData({
            'from.idCardType': this.data.idCardTypeTpy,
        });
    },


    onFromClose: function () {
        wx.navigateBack();
    },
    onFromSave: function () {
    },
});